Skip to content

refactor(wait_for_status): Use self.instance to get status#2499

Merged
myakove merged 4 commits into
mainfrom
wait_for_status-use-instance
Aug 16, 2025
Merged

refactor(wait_for_status): Use self.instance to get status#2499
myakove merged 4 commits into
mainfrom
wait_for_status-use-instance

Conversation

@myakove

@myakove myakove commented Aug 13, 2025

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • None
  • Improvements

    • More reliable and efficient resource status polling during waits.
    • Reduced logging noise by only reporting status changes.
    • Early exit when encountering terminal failure statuses.
    • Clearer timeout messages that include the last-known status.
  • Bug Fixes

    • Fixes issues from parsing list-style responses for status.
    • Prevents redundant logs during long-running waits.

@coderabbitai

coderabbitai Bot commented Aug 13, 2025

Copy link
Copy Markdown

Walkthrough

Reworks wait_for_status in ocp_resources/resource.py to poll resource status by sampling self.exists via a lambda and extracting status with sample.to_dict().get("status", {}).get("phase"); removes field_selector/namespace from TimeoutSampler, logs only on status changes, returns on desired status, and raises on stop_status (default FAILED) while preserving TimeoutExpiredError handling.

Changes

Cohort / File(s) Change summary
Resource status polling refactor
ocp_resources/resource.py
Rewrote wait_for_status to use a lambda sampling self.exists and read status.phase via sample.to_dict(); removed field_selector and namespace from TimeoutSampler; adjusted loop to compute current_status, track and log only status transitions (last_logged_status), return on desired status, raise on stop_status (FAILED default), and preserve TimeoutExpiredError handling with current-status logging when available.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these settings in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between e7ddd30 and bc36a78.

📒 Files selected for processing (1)
  • ocp_resources/resource.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • ocp_resources/resource.py
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch wait_for_status-use-instance

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@redhat-qe-bot1

Copy link
Copy Markdown

Report bugs in Issues

Welcome! 🎉

This pull request will be automatically processed with the following features:

🔄 Automatic Actions

  • Reviewer Assignment: Reviewers are automatically assigned based on the OWNERS file in the repository root
  • Size Labeling: PR size labels (XS, S, M, L, XL, XXL) are automatically applied based on changes
  • Issue Creation: A tracking issue is created for this PR and will be closed when the PR is merged or closed
  • Pre-commit Checks: pre-commit runs automatically if .pre-commit-config.yaml exists
  • Branch Labeling: Branch-specific labels are applied to track the target branch
  • Auto-verification: Auto-verified users have their PRs automatically marked as verified

📋 Available Commands

PR Status Management

  • /wip - Mark PR as work in progress (adds WIP: prefix to title)
  • /wip cancel - Remove work in progress status
  • /hold - Block PR merging (approvers only)
  • /hold cancel - Unblock PR merging
  • /verified - Mark PR as verified
  • /verified cancel - Remove verification status

Review & Approval

  • /lgtm - Approve changes (looks good to me)
  • /approve - Approve PR (approvers only)
  • /automerge - Enable automatic merging when all requirements are met (maintainers and approvers only)
  • /assign-reviewers - Assign reviewers based on OWNERS file
  • /assign-reviewer @username - Assign specific reviewer
  • /check-can-merge - Check if PR meets merge requirements

Testing & Validation

  • /retest tox - Run Python test suite with tox
  • /retest python-module-install - Test Python package installation
  • /retest conventional-title - Validate commit message format
  • /retest all - Run all available tests

Container Operations

  • /build-and-push-container - Build and push container image (tagged with PR number)
    • Supports additional build arguments: /build-and-push-container --build-arg KEY=value

Cherry-pick Operations

  • /cherry-pick <branch> - Schedule cherry-pick to target branch when PR is merged
    • Multiple branches: /cherry-pick branch1 branch2 branch3

Label Management

  • /<label-name> - Add a label to the PR
  • /<label-name> cancel - Remove a label from the PR

✅ Merge Requirements

This PR will be automatically approved when the following conditions are met:

  1. Approval: /approve from at least one approver
  2. LGTM Count: Minimum 0 /lgtm from reviewers
  3. Status Checks: All required status checks must pass
  4. No Blockers: No WIP, hold, or conflict labels
  5. Verified: PR must be marked as verified (if verification is enabled)

📊 Review Process

Approvers and Reviewers

Approvers:

  • myakove
  • rnetser

Reviewers:

  • dbasunag
  • myakove
  • rnetser
Available Labels
  • hold
  • verified
  • wip
  • lgtm
  • approve
  • automerge

💡 Tips

  • WIP Status: Use /wip when your PR is not ready for review
  • Verification: The verified label is automatically removed on each new commit
  • Cherry-picking: Cherry-pick labels are processed when the PR is merged
  • Container Builds: Container images are automatically tagged with the PR number
  • Permission Levels: Some commands require approver permissions
  • Auto-verified Users: Certain users have automatic verification and merge privileges

For more information, please refer to the project documentation or contact the maintainers.

Comment thread ocp_resources/resource.py Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🔭 Outside diff range comments (1)
ocp_resources/resource.py (1)

966-974: Respect the Resource.status accessor and tolerate transient NotFound/AttributeError

Polling self.instance.status.phase bypasses per-resource status logic. I scanned the repo and found resource.status is a @Property at ocp_resources/resource.py:1052 and node_network_configuration_policy.status is a @Property at ocp_resources/node_network_configuration_policy.py:364 — so use the resource accessor instead of touching self.instance directly. Also the TimeoutSampler at ocp_resources/resource.py:966–974 omits NOT_FOUND handling (other samplers e.g. around line 905 include it) and should tolerate AttributeError while status fields settle.

Please apply this change:

  • Locations to fix:
    • ocp_resources/resource.py — TimeoutSampler at ~lines 966–974 (replace polling and exceptions)
    • Review other TimeoutSampler usages for consistency: lines 901, 927, 966, 1109, 1234, 1242, 1294, 1302

Suggested diff:

         samples = TimeoutSampler(
             wait_timeout=timeout,
             sleep=sleep,
-            exceptions_dict={
-                **PROTOCOL_ERROR_EXCEPTION_DICT,
-                **DEFAULT_CLUSTER_RETRY_EXCEPTIONS,
-            },
-            func=lambda: self.instance.status.phase,
+            exceptions_dict={
+                **PROTOCOL_ERROR_EXCEPTION_DICT,
+                **DEFAULT_CLUSTER_RETRY_EXCEPTIONS,
+                **NOT_FOUND_ERROR_EXCEPTION_DICT,
+                AttributeError: [],
+            },
+            # Respect per-resource status implementations (support method or property).
+            func=lambda: (self.status() if callable(getattr(self, "status", None)) else getattr(self, "status", None)),
         )

This preserves per-resource overrides and avoids premature failures while a resource's status settles.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0bc2e5c and e7ddd30.

📒 Files selected for processing (1)
  • ocp_resources/resource.py (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
ocp_resources/resource.py (1)
ocp_resources/node_network_configuration_policy.py (1)
  • status (364-367)

Comment thread ocp_resources/resource.py
Comment thread ocp_resources/resource.py
@myakove

myakove commented Aug 16, 2025

Copy link
Copy Markdown
Collaborator Author

/verified
/approve

@myakove myakove merged commit 9710e9e into main Aug 16, 2025
7 checks passed
@myakove myakove deleted the wait_for_status-use-instance branch August 16, 2025 09:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants